package com.hzy.servlet;

import com.hzy.pojo.Rent;
import com.hzy.service.RentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.smartcardio.Card;
import java.io.IOException;

/**
 * @Package: com.hzy.servlet
 * @ClassName: InfoServlet
 * @Author: 862982795
 * @CreateTime: 2021/06/23 20:59
 * @Description:
 */
@WebServlet("/InfoServlet")
public class InfoServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        RentService service = new RentService();

        Integer id = Integer.parseInt(request.getParameter("id"));
        String operating = request.getParameter("operating");

        Rent rent = service.queryRentById(id);

        request.setAttribute("rent", rent);
        if (operating.equals("查看")) {
            request.getRequestDispatcher("info.jsp").forward(request, response);
        } else {
            request.getSession().setAttribute("id", id);
            request.getRequestDispatcher("update.jsp").forward(request, response);
        }

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
